package com.sort.select;

public class SelectSort {
    private int[] array;

    public SelectSort(int[] array) {
        this.array = array;
    }

    public int[] sort() {

        for(int i = 0; i < array.length - 1; i++) {
            int min = array[i];
            int minIndex = i;

            for(int j = i + 1; j < array.length; j++) {
                if (min > array[j]) {
                    minIndex = j;
                    min = array[j];
                }
            }

            if(minIndex != i) {
                array[minIndex] = array[i];
                array[i] = min;
            }
        }

        return this.array;
    }
}
